﻿var $navel = $('#sidebar ul li');

window.onload = UpdateNav();

function UpdateNav() {
    var page = $('#content_page').attr("class");
    for (var i = 0; i < $navel.length; i++) {
        if ($($navel[i]).attr("id") == page) {
            $($navel[i]).addClass("active");
        }
    }
}

$('#data_content tr td').live('click', function () {
    var els = $(this).parent().find('td');
    for (var i = 0; i < els.length; i++) {
        if ($(els[i]).attr("name") == 'id') {
            $('#EditForm label[name="id"]').text(els[i].innerText);
            $('#EditForm input[name="id"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'number') {
            $('#EditForm input[name="number"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'area') {
            $('#EditForm input[name="area"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'xlocation') {
            $('#EditForm input[name="xlocation"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'ylocation') {
            $('#EditForm input[name="ylocation"]').val(els[i].innerText);
        }else if ($(els[i]).attr("name") == 'location') {
            $('#EditForm input[name="location"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'totalSegment') {
            $('#EditForm input[name="totalSegment"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'fullname') {
            $('#EditForm input[name="fullname"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'beginPoint') {
            $('#EditForm input[name="beginPoint"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'endPoint') {
            $('#EditForm input[name="endPoint"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'info') {
            $('#EditForm input[name="info"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'picture') {
            $('#EditForm input[name="picture"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'phone') {
            $('#EditForm input[name="phone"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'website') {
            $('#EditForm input[name="website"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'addr') {
            $('#EditForm input[name="addr"]').val(els[i].innerText);
        } else if ($(els[i]).attr("name") == 'type') {
            $('#EditForm input[name="type"]').val(els[i].innerText);
        }
    }
});

$('#copyabove').live('click', function () {
    //$('#AddForm label[name="id"]').text($('#EditForm label[name="id"]').text());    
    try { $('#AddForm input[name="number"]').val($('#EditForm input[name="number"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="area"]').val($('#EditForm input[name="area"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="xlocation"]').val($('#EditForm input[name="xlocation"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="ylocation"]').val($('#EditForm input[name="ylocation"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="id"]').val($('#EditForm input[name="id"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="location"]').val($('#EditForm input[name="location"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="totalSegment"]').val($('#EditForm input[name="totalSegment"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="beginPoint"]').val($('#EditForm input[name="beginPoint"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="endPoint"]').val($('#EditForm input[name="endPoint"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="fullname"]').val($('#EditForm input[name="fullname"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="addr"]').val($('#EditForm input[name="addr"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="info"]').val($('#EditForm input[name="info"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="website"]').val($('#EditForm input[name="website"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="phone"]').val($('#EditForm input[name="phone"]').val()); } catch (ex) { }
    try { $('#AddForm input[name="type"]').val($('#EditForm input[name="type"]').val()); } catch (ex) { }
});

function SubmitForm(id) {
    $('#' + id).submit();
}